#!/bin/sh

echo "($0)"

#################################
# Modifying /etc/init.d/syslogd
#################################
#echo -n "Modifying /etc/init.d/syslogd ... "
#cat $DEST/etc/init.d/sysklogd | \
#sed -e 's/^SYSLOGD=\"\"/SYSLOGD\=\"\-p \/rw\/dev\/log \-m 0\"/' \
#>  $DEST/etc/init.d/sysklogd.tmp
#mv  $DEST/etc/init.d/sysklogd.tmp  $DEST/etc/init.d/sysklogd
#chmod +x $DEST/etc/init.d/sysklogd
#echo "Done"

#################################
# Modifying /etc/mtab
#################################
echo -n "Modifying /etc/mtab ... "
rm -f /etc/mtab
ln -s /proc/mounts /etc/mtab
echo "Done"

#################################
# Modifying /etc/network/options
#################################
#echo -n "Modifying /etc/network/options ... "
#touch /etc/network/options 
#echo ip_forward=yes >> /etc/network/options 
#echo spoofprotect=yes >> /etc/network/options 
#echo syncookies=no >> /etc/network/options 
##sed -i -e "s/ip_forward=no/ip_forward=yes/" /etc/network/options 
#echo "Done"

#################################
# Adding configuration for watchdog
#################################
echo -n "Adding configuration for watchdog ... "
WATCHDOG_CONF=/etc/watchdog.conf
if [ -f $WATCHDOG_CONF ] ; then
	echo "watchdog-device = /dev/watchdog" >> $WATCHDOG_CONF
	echo "interval	    = 15" >> $WATCHDOG_CONF
	mknod -m 600 /dev/wd c 10 130
fi;
echo "Done"

#################################
# Modifying /etc/init.d/mountall.sh
#################################
#echo -n "Modifying /etc/init.d/mountall.sh ... "

mkdir /ro
#echo "tar -C /ro -cf - . | tar -C /lib/init/rw -xf -  > /dev/null 2>&1" >> /etc/init.d/mountall.sh

#cat >> /etc/init.d/mountall.sh <<EOF
#mkdir -p /rw/var/log > /dev/null 2>&1
#mount -t aufs -o dirs=/rw/var/log:/var/log=ro none /var/log  > /dev/null 2>&1
#mkdir -p /rw/var/tmp > /dev/null 2>&1
#mount -t aufs -o dirs=/rw/var/tmp:/var/tmp=ro none /var/tmp  > /dev/null 2>&1
#mkdir -p /rw/tmp > /dev/null 2>&1
#mount -t aufs -o dirs=/rw/tmp:/tmp=ro none /tmp  > /dev/null 2>&1
#EOF

#echo "Done"

#################################
# Enable RAMRUN and RAMLOCK in /etc/default/rcS
#################################
echo -n "Enable RAMRUN and RAMLOCK in /etc/default/rcS"
cat >> /etc/default/rcS <<EOF
RAMRUN=yes
RAMLOCK=yes
EOF
echo "Done"

#################################
# Enable RAMRUN and RAMLOCK in /etc/default/rcS
#################################
echo -n "change /etc/default/tmpfs"
cat >> /etc/default/tmpfs << EOF
TMPFS_SIZE=50%
EOF
echo "Done"

#################################
# Add voyage-sync to rc.d
#################################
#echo -n "Add voyage-sync to rc.d "

#update-rc.d voyage-sync start 36 S . start 36 0 6 .
#mv /etc/rc0.d/K99voyage-sync /etc/rc0.d/S36voyage-sync 
#mv /etc/rc6.d/K99voyage-sync /etc/rc6.d/S36voyage-sync 


#################################
# Modifying /etc/modules
#################################
echo -n "Modifying /etc/modules and /etc/modprobe.d/ ... "

echo "Done"

#################################
# Modifying /etc/sysctl.conf
#################################
echo -n "Modifying /etc/sysctl.conf ... "
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo "net.ipv4.conf.default.rp_filter=1" >> /etc/sysctl.conf
echo "net.ipv4.conf.all.rp_filter=1" >> /etc/sysctl.conf
echo "net.ipv4.tcp_syncookies=0" >> /etc/sysctl.conf
echo "kernel.panic=30" >> /etc/sysctl.conf

echo "" >> /etc/sysctl.conf
echo "## pdflush settings for heavy write operations on CF" >> /etc/sysctl.conf
echo "#vm.dirty_expire_centisecs=500" >> /etc/sysctl.conf
echo "#vm.dirty_bytes=1024000" >> /etc/sysctl.conf
echo "#vm.dirty_writeback_centisecs=100" >> /etc/sysctl.conf

echo "Done"

#################################
# Modifying /root/.bashrc
#################################
echo -n "Modifying /root/.bashrc ... "
#echo ". /etc/bash_completion" >> /root/.bashrc
echo "alias bc='. /etc/bash_completion'" >> /root/.bashrc

echo "Done"

#################################
# Modifying /etc/hosts
#################################
echo -n "Modifying /etc/hosts ... "
echo "127.0.0.1 localhost voyage" >> /etc/hosts
echo "127.0.1.1 voyage" >> /etc/hosts
echo "Done"


#################################
# Modifying /etc/apt/sources.list
#################################
echo -n "Modifying /etc/apt/sources.list ... "
echo "" >> /etc/apt/sources.list
echo "# Primary Debian Mirror Sites (http://www.debian.org/mirror/list)" >> /etc/apt/sources.list
wget http://www.debian.org/mirror/list -O - | \
sed -n  -e "/td.*href=\"http:\/\/ftp\.[a-z][a-z]\.debian\.org/ P" | \
sed -e "s/^.*href=\"//g" -e "s/\">.*$//g" -e "s/^/#deb /g" | \
sed -e "s/$/ wheezy main contrib non-free/g" | sort -u \
>> /etc/apt/sources.list

echo "Done"

#################################
# Modifying /etc/usbmount/usbmount.conf
#################################
#echo -n "Modifying /etc/usbmount/usbmount.conf ... "
#
#echo "FS_MOUNTOPTIONS=\"-fstype=vfat,utf8 -fstype=fat,utf8\"" >> /etc/usbmount/usbmount.conf

#################################
# Modifying /etc/usbmount/usbmount.conf
#################################
echo -n "Modifying /etc/usbmount/usbmount.conf ... "

echo "FS_MOUNTOPTIONS=\"-fstype=vfat,utf8 -fstype=fat,utf8 -fstype=ntfs,utf8\"" >> /etc/usbmount/usbmount.conf
echo "FILESYSTEMS=\"vfat ext2 ext3 ext4 hfsplus ntfs\"" >> /etc/usbmount/usbmount.conf

echo "Done"

#################################
# Modifying /etc/dhcp/dhclient.conf
#################################
echo -n "Modifying /etc/dhcp/dhclient.conf ... "

cat >> /etc/dhcp/dhclient.conf <<EOF

lease {
  interface "eth0";
  fixed-address 10.0.0.10;
  medium "link0 link1";
  option subnet-mask 255.255.255.0;
  renew 2 2022/1/1 00:00:01;
  rebind 2 2022/1/1 00:00:01;
  expire 2 2022/1/1 0:00:01;
}

EOF

echo "Done."

